﻿using System;
using System.Threading;

namespace 禁止休眠
{
    class Program
    {
        static void Main(string[] args)
        {
            bool KeepScreenOpen = false;
            char[] c = { '-','\\','|','/'};
            foreach (string arg in args)
            {
                if (arg.ToLower().Trim() == "-s")
                    KeepScreenOpen = true;

                if (arg.ToLower().Trim() == "-?")
                {
                    Console.WriteLine("默认情况下仅阻止休眠。");
                    Console.WriteLine("参数:");
                    Console.WriteLine("-s 阻止屏幕关闭");
                    Console.WriteLine("-? 参数帮助");
                }
                    
            }
            Console.WriteLine(DateTime.Now.ToString());
            SystemSleep.PreventForCurrentThread(KeepScreenOpen);
            Console.Write("正在阻止"+(KeepScreenOpen?"息屏和休眠":"休眠")+"，关闭本程序解除... ");
            while (true)
            {
                for (int i = 0; i < c.Length; i++)
                {
                    Console.Write("\b"+c[i]);
                    Thread.Sleep(1000);
                }
                
            }
        }
    }
}
